package com.bestcem.xm.deliver.enums;

import cn.hutool.core.util.EnumUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum RespondentStatusEnum {

    RESPONDENT_STATUS_NOTSTART(101, "未开始"),
    RESPONDENT_STATUS_BEGIN(0, "进行中"),
    RESPONDENT_STATUS_FINISH(1, "成功完成"),
    RESPONDENT_STATUS_SCREEN_OUT(2, "被甄别"),
    RESPONDENT_STATUS_QUOTA_FULL(3, "配额满"),
    RESPONDENT_STATUS_SYSTEM_SCREEN_OUT(4, "系统甄别"),
    RESPONDENT_STATUS_HIDDEN(5, "成功完成(隐藏)"),
    RESPONDENT_STATUS_BACKUP(6, "备用"),
    RESPONDENT_STATUS_DISCARD(7, "废弃"),
    RESPONDENT_STATUS_OVERFULL(8, "超额"),
    RESPONDENT_STATUS_OPEN(9, "已打开"),
    RESPONDENT_STATUS_UNFINISH(10, "未完成"),
    RESPONDENT_STATUS_DELETE(107, "彻底删除");

    @EnumValue
    private final int value;
    private final String desc;

    public static RespondentStatusEnum getRandomEnum(int index) {
        return EnumUtil.getEnumAt(RespondentStatusEnum.class, index);
    }

    public static String getDescByValue(int value) {
        List<RespondentStatusEnum> collect = Arrays.stream(RespondentStatusEnum.values()).filter(one -> one.getValue() == value)
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(collect)) {
            return "";
        } else {
            return Objects.requireNonNull(collect.stream().findFirst().orElse(null)).getDesc();
        }
    }

    public static List<Integer> getSubmitStatus() {
        List<Integer> result = new ArrayList<>();
        result.add(RESPONDENT_STATUS_DISCARD.getValue());
        result.add(RESPONDENT_STATUS_FINISH.getValue());
        result.add(RESPONDENT_STATUS_SCREEN_OUT.getValue());
        result.add(RESPONDENT_STATUS_QUOTA_FULL.getValue());
        result.add(RESPONDENT_STATUS_BACKUP.getValue());
        result.add(RESPONDENT_STATUS_OVERFULL.getValue());
        result.add(RESPONDENT_STATUS_HIDDEN.getValue());
        result.add(RESPONDENT_STATUS_UNFINISH.getValue());
        return result;
    }
}
